package com.xzy.c;

import com.xzy.a.UserService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
 * 说明：
 * 1、ClassPathXmlApplicationContext与FileSystemXmlApplicationContext
 * 2、基于XML配置Bean与基于Java类配置Bean
 *
 * @author xzy
 * @date 2021/11/29 22:51
 */
public class Main {
    public static void main(String[] args) {
        method1();
        method2();
        method3();
    }

    public static void method1() {
        // 基于classpath的相对路径
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("beanConfig.xml");
        System.out.println(applicationContext.getBean(UserService.class));
    }

    public static void method2() {
        // 基于工程的相对路径
        FileSystemXmlApplicationContext applicationContext1 = new FileSystemXmlApplicationContext("demo2\\src\\main\\resources\\beanConfig.xml");
        System.out.println(applicationContext1.getBean(UserService.class));


        // 文件系统绝对路径
        FileSystemXmlApplicationContext applicationContext2 = new FileSystemXmlApplicationContext("E:\\Programing\\spring-learning\\spring-zhouyu\\demo2\\src\\main\\resources\\beanConfig.xml");
        System.out.println(applicationContext2.getBean(UserService.class));
    }

    public static void method3() {
        // 基于Java配置类
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(BeanConfig.class);
        System.out.println(applicationContext.getBean(UserService.class));
    }
}
